package org.bees.cms.web.util.velocity.editer;

import java.io.Serializable;
import java.util.Map;

import org.bees.cms.web.util.Beans;

public class RadioEditer extends AbstractMultipleEditer {

	@Override
	public String edit(Serializable t) throws Exception {
		value = t == null ? value : Beans.getString(t, property);
		id = id.equals("") ? name : id;
		StringBuilder builder = new StringBuilder();
		int count = 0;
		for (Map.Entry<String, String> entry : map.entrySet()) {
			count += 1;
			builder.append("<input id='" + id + "_" + count + "'");
			builder.append(" class='" + clazz + "'");
			builder.append(" style='" + style + "'");
			builder.append(" type='radio'");
			builder.append(" name='" + name + "'");
			builder.append(" value='" + entry.getValue() + "'");
			builder.append(value.equals(entry.getValue()) ? " checked='checked'" : "");
			builder.append(" validator='" + validator + "'");
			builder.append(" />");

			builder.append("<label for='" + id + "_" + count + "'>");
			builder.append(entry.getKey());
			builder.append("</label>");

			builder.append(gap);
		}
		return builder.toString();
	}

}
